<script setup lang="ts">
import {ref} from "vue";
import AddOrUpdate from "@/views/dossier/add-or-update.vue";
import {useUserStore} from "@/store/modules/user";
import {useTeacherFileInfoApi, useTeacherInfoApi} from "@/api/college/teacher";
import { useStudentFileInfoApi, useStudentInfoApi } from "@/api/college/student";

const props = defineProps({
  studentId: {
    type: String
  },
  edit: {
    type: Boolean,
    default: false
  }
})

const addOrUpdateRef = ref()
const baseData = ref<any>({})
const userStore = useUserStore()
const isTeacher: boolean = userStore.user.roleIdList[0] === 1
getDataList()

/**
 * 获取数据
 */
function getDataList(){
  if(props.studentId) {
    useStudentInfoApi(props.studentId).then(res=>{
      Object.assign(baseData.value, res.data)
    })
    return
  }
  if(isTeacher) useTeacherFileInfoApi(userStore.user.id).then(res=>{
      Object.assign(baseData.value, res.data)
    })
  else useStudentFileInfoApi(userStore.user.id).then(res=>{
    Object.assign(baseData.value, res.data)
  })
}

function informationSave(){
  addOrUpdateRef.value.init({
    id:baseData.value.id,
    name: baseData.value.name,
    group: baseData.value.group,
    origin: baseData.value.origin,
    idNum: baseData.value.idNum,
    birthTime: baseData.value.birthTime,
    sex: baseData.value.sex,
    address: baseData.value.address,
    politicalAspects: baseData.value.politicalAspects,
    phone: baseData.value.phone,
    email: baseData.value.email,
    academyId: baseData.value.academyId,
    code: baseData.value.code
  })
}
</script>

<template>
<el-card>
  <h1 style="">基本信息</h1>
  <el-button type="primary" style="position: absolute; right: 40px; top: 30px" @click="informationSave" v-if="!props.edit">修改信息</el-button>
 <div style="display: flex; margin-top: 15px">
   <el-image style="width: 100px; height: 100px;" src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"/>
   <el-descriptions :column="4" style="flex: 1; margin-left: 20px">
     <el-descriptions-item label="姓名">{{baseData?.name}}</el-descriptions-item>
     <el-descriptions-item label="年龄">18</el-descriptions-item>
     <el-descriptions-item label="民族">{{baseData?.group}}</el-descriptions-item>
     <el-descriptions-item label="籍贯">{{baseData?.origin}}</el-descriptions-item>
     <el-descriptions-item label="身份证号码">{{baseData?.idNum}}</el-descriptions-item>
     <el-descriptions-item label="出生年月日">{{baseData?.birthTime}}</el-descriptions-item>
     <el-descriptions-item label="性别">{{ baseData?.sex === 1? "男" : "女" }}</el-descriptions-item>
     <el-descriptions-item label="居住地址">{{baseData?.address}}</el-descriptions-item>
     <el-descriptions-item label="政治面貌">{{baseData?.politicalAspects}}</el-descriptions-item>
     <el-descriptions-item label="手机号">{{baseData?.phone}}</el-descriptions-item>
     <el-descriptions-item label="邮箱">{{baseData?.email}}</el-descriptions-item>
     <el-descriptions-item ></el-descriptions-item>
   </el-descriptions>
 </div>
  <el-descriptions title="教资相关情况" :column="3" v-if="isTeacher">
    <el-descriptions-item label="工号">{{baseData?.code}}</el-descriptions-item>
    <el-descriptions-item label="任职类别">{{baseData?.category}}</el-descriptions-item>
    <el-descriptions-item label="编制情况">{{baseData?.preparation}}</el-descriptions-item>
    <el-descriptions-item label="专业技术职务">{{baseData?.office}}</el-descriptions-item>
    <el-descriptions-item label="教师资格证种类">{{baseData?.cert}}</el-descriptions-item>
    <el-descriptions-item label="发证机关">{{baseData?.authority}}</el-descriptions-item>
    <el-descriptions-item label="教师资格证号码">{{baseData?.certNum}}</el-descriptions-item>
    <el-descriptions-item label="最高学历">{{baseData?.education}}</el-descriptions-item>
    <el-descriptions-item label="学位">{{baseData?.degree}}</el-descriptions-item>
    <el-descriptions-item label="学籍状态">{{baseData?.studentStatus}}</el-descriptions-item>
    <el-descriptions-item label="毕业时间">{{baseData?.graduationTime}}</el-descriptions-item>
  </el-descriptions>
  <el-descriptions title="学籍" :column="3" v-else>
    <el-descriptions-item label="学号">{{baseData?.code}}</el-descriptions-item>
    <el-descriptions-item label="院校名称">麻绳理工</el-descriptions-item>
    <el-descriptions-item label="分院">{{baseData?.academyName}}</el-descriptions-item>
    <el-descriptions-item label="专业">{{baseData?.specializedName}}</el-descriptions-item>
    <el-descriptions-item label="班级">{{baseData?.className}}</el-descriptions-item>
    <el-descriptions-item label="层次">{{baseData?.level}}</el-descriptions-item>
    <el-descriptions-item label="学制">{{baseData?.academic}}</el-descriptions-item>
    <el-descriptions-item label="学历类别">{{baseData?.degreeType}}</el-descriptions-item>
    <el-descriptions-item label="入学日期">{{ baseData?.enrollmentDate }}</el-descriptions-item>
    <el-descriptions-item label="学籍状态">{{baseData?.studentStatus}}</el-descriptions-item>
  </el-descriptions>
<!--  <el-descriptions title="家庭信息" :column="4">-->
<!--    <el-table>-->
<!--      <el-table-column label="称谓"></el-table-column>-->
<!--      <el-table-column label="姓名"></el-table-column>-->
<!--      <el-table-column label="政治面貌"></el-table-column>-->
<!--      <el-table-column label="联系电话"></el-table-column>-->
<!--      <el-table-column label="工作单位及职务"></el-table-column>-->
<!--    </el-table>-->
<!--  </el-descriptions>-->
</el-card>
  <add-or-update ref="addOrUpdateRef" @refresh-data-list="getDataList"></add-or-update>
</template>

<style scoped>
>>>.el-descriptions__table tr{
  display: flex;
}
>>>.el-descriptions__table tr td{
  flex: 1;
}
</style>
